package com.bytedance.common.utility.collection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.WeakHashMap;

public final class WeakList<E> implements Iterable<E> {
    public final WeakHashMap<E, Object> weakHashMap = new WeakHashMap<>();
    private final Object obj = new Object();

    public final void add(E v) {
        if (v == null) {
            this.weakHashMap.size();
        } else {
            this.weakHashMap.put(v, this.obj);
        }
    }

    public final void remove(E v) {
        if (v == null) {
            this.weakHashMap.size();
        } else {
            this.weakHashMap.remove(v);
        }
    }

    public final Iterator<E> iterator() {
        ArrayList arrayList = new ArrayList(this.weakHashMap.size());
        Iterator<E> iterator = this.weakHashMap.keySet().iterator();
        while (iterator.hasNext()) {
            E v = iterator.next();
            if (v == null) {
                continue;
            }

            arrayList.add(v);
        }
        return arrayList.iterator();
    }
}

